// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuex from 'vuex'
import store from './store/store'

// 引入整个Element组件库
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

// 导入字体图标
import './assets/fonts/iconfont.css'

// import axios from 'axios'
// axios.defaults.baseURL = "http://d299o16972.qicp.vip/"

// // // 配置请求拦截器
// axios.interceptors.request.use(config => {
//   config.headers.Authorization=JSON.parse(window.sessionStorage.getItem('userInfo')).access_token
//   console.log(config)
//   // config.headers.Authorization=window.sessionStorage.getItem('access_token')
//   return config
// })
// Vue.prototype.$http=axios

Vue.use(ElementUI)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

// 拦截器
router.beforeEach((to, from, next)=> {
  let userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
  if (userInfo && userInfo.access_token) {
    console.log(userInfo)
    next()
  } else {
    next('/login')
  }
})